package com.edu.zju.scs.panacea.controller.plan;

import com.edu.zju.scs.panacea.entity.BaseResult;
import com.edu.zju.scs.panacea.entity.resource.Site;
import com.edu.zju.scs.panacea.service.plan.MaterialService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author: Yue Liang
 * @Date: 2019-01-14 14:11
 */
@Controller
@EnableAutoConfiguration
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    @ResponseBody
    @ApiOperation(value = "查询某个站点下的所有审核素材", notes = "查询某个站点下的所有审核素材")
    @RequestMapping(value = "/material/site", method = RequestMethod.POST)
    public BaseResult getLocBySiteId(HttpSession session) {
        Site site = (Site) session.getAttribute("site");
        BaseResult baseResult = materialService.getMaterialCheckBySite(site.getId());
        return baseResult;
    }

    @ResponseBody
    @ApiOperation(value = "根据id查询某个素材", notes = "根据id查询某个素材")
    @RequestMapping(value = "/material/info/{id}", method = RequestMethod.GET)
    public BaseResult getMaterial(@PathVariable Long id) {
        return materialService.getMaterial(id);
    }


    @ResponseBody
    @ApiOperation(value = "根据id查询某个素材", notes = "根据id查询某个素材")
    @RequestMapping(value = "/material/audit", method = RequestMethod.POST)
    public BaseResult auditMaterial(
            @ApiParam("id") @RequestParam(value = "id") Long id,
            @ApiParam("操作类型") @RequestParam(value = "type") Integer type,
            @ApiParam("失败原因填写") @RequestParam(value = "remark", required = false) String remark) {
        return materialService.auditMaterial(id, type, remark);
    }

    @ResponseBody
    @ApiOperation(value = "根据id查询素材列表", notes = "根据id查询素材列表")
    @RequestMapping(value = "/material/launch", method = RequestMethod.POST)
    public BaseResult launchMaterial(
            @ApiParam("locId") @RequestParam(value = "locId") Long locId) {
        return materialService.launchMaterial(locId);
    }
}